package HibernateSQLite.java.util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil{
	
	public static final SessionFactory sessionFactory;
	public static final SessionFactory SessionHistoryFactory;
	//public static final SchemaExport schemaExport;
	
	
	
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}	
	public static void closeSession(){
		getSessionFactory().close();
	}
	public static SessionFactory getSessionHistoryFactory() {
		return SessionHistoryFactory;
	}
	
	public static void closeHistorySession(){
		getSessionHistoryFactory().close();
	}

	static {
		try{
			sessionFactory = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
			SessionHistoryFactory = new Configuration().configure("/hibernate-history.cfg.xml").buildSessionFactory();
		}catch(Throwable e){
			System.out.println("Initial SessionFactory creation failed: "+e);
			throw new ExceptionInInitializerError(e);
		}
	}
	
	
}
